from django import forms

from demo.models import Classes, Label


class ArticleForm(forms.Form):
    title = forms.CharField(
        label='标题',
        max_length=30,
        min_length=2,
        error_messages={
            'min_length': '标题长度不能小于2',
            'max_length': '标题长度不能大于30'
        }
    )
    desc = forms.CharField(
        label='文章简介',
        max_length=100,
        min_length=10,
        error_messages={
            'min_length': '简介长度不能小于10',
            'max_length': '简介长度不能大于100'
        }

    )
    content = forms.CharField(
        label='文章内容',
        widget=forms.Textarea
    )
    cover = forms.FileField(
        label='封面图',
    )
    # 分类是让用户自己选择的
    classes = forms.ModelChoiceField(
        label='分类',
        queryset=Classes.objects.all(),
        empty_label=None
    )
    # 标签为多选字段,多对多
    label = forms.ModelMultipleChoiceField(
        label='标签',
        queryset=Label.objects.all(),
    )
